package pojo;

import annotation.fields;
import annotation.table;

/**
 * 用户的实体类
 */
//yonghu表名
@table(value = "yonghu")
public class User {
    @fields(colounmName = "uid")
    private Integer uid;
    @fields(colounmName = "usename")
    private String usename;
    @fields(colounmName = "password")
    private String password;
    @fields(colounmName = "gender")
    private String gender;
    @fields(colounmName = "telephone")
    private String telephone;
    @fields(colounmName = "age")
    private String age;
    @fields(colounmName = "addpower")
    private Integer addpower;
    @fields(colounmName = "mid")
    private Integer mid;

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUsename() {
        return usename;
    }

    /**
     * 检验用户名
     *
     * @param usename
     * @return
     */
    public boolean checkUsename(String usename) {
        String regExp = "^[\u4e00-\u9fa5_a-zA-Z0-9]{1,9}$";
        if (usename.matches(regExp)) {
            return true;
        } else
            return false;
    }

    public boolean setUsename(String usename) {
        if (checkUsename(usename)) {
            this.usename = usename;
            return true;
        } else return false;
    }

    public String getPassword() {
        return password;
    }

    /**
     * 检验密码
     *
     * @param password
     * @return
     */
    public boolean checkPassword(String password) {
        String regExp = "^[A-Za-z0-9]{6,13}$";
        if (password.matches(regExp)) {
            return true;
        } else
            return false;
    }

    public boolean setPassword(String password) {
        if (checkPassword(password)) {
            this.password = password;
            return true;
        } else return false;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getTelephone() {
        return telephone;
    }

    /**
     * 检验电话号码
     *
     * @param telephone
     * @return
     */
    public boolean checkTelephone(String telephone) {
        String regExp = "^[0-9]{11}$";
        if (telephone.matches(regExp)) {
            return true;
        } else
            return false;
    }

    public boolean setTelephone(String telephone) {
        if (checkTelephone(telephone)) {
            this.telephone = telephone;
            return true;
        } else return false;
    }

    public String getAge() {
        return age;
    }

    /**
     * 检验年龄
     *
     * @param age
     * @return
     */
    public boolean checkAge(String age) {
        String regExp = "^[0-9]{1,3}$";
        if (age.matches(regExp)) {
            return true;
        } else
            return false;
    }

    public boolean setAge(String age) {
        if (checkAge(age)) {
            this.age = age;
            return true;
        } else return false;
    }

    public Integer getAddpower() {
        return addpower;
    }

    public void setAddpower(Integer addpower) {
        this.addpower = addpower;
    }

    public Integer getMid() {
        return mid;
    }

    public void setMid(Integer mid) {
        this.mid = mid;
    }

    @Override
    public String toString() {
        return "User{" +
                "uid=" + uid +
                ", usename='" + usename + '\'' +
                ", password='" + password + '\'' +
                ", gender='" + gender + '\'' +
                ", telephone='" + telephone + '\'' +
                ", age='" + age + '\'' +
                ", addpower=" + addpower +
                ", mid=" + mid +
                '}';
    }

    public User() {
    }

    public User(Integer uid, String usename, String password, String gender, String telephone, String age, Integer addpower, Integer mid) {
        this.uid = uid;
        this.usename = usename;
        this.password = password;
        this.gender = gender;
        this.telephone = telephone;
        this.age = age;
        this.addpower = addpower;
        this.mid = mid;
    }
}
